﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using Barbar.UrlGuard.Properties;

namespace Barbar.UrlGuard.Controls {
  public class MainContextMenuStrip : ContextMenuStrip, ILocalizable {
    private ToolStripButton m_ShowStatus;
    private ToolStripButton m_ShowConfiguration;
    private ToolStripButton m_ShowAbout;
    private ToolStripButton m_Exit;

    public event EventHandler<MainContextMenuEventArgs> Command;

    public MainContextMenuStrip() {
      m_ShowStatus = new ToolStripButton("Show status", Resources.icon_menu_status, OnMenuClick);
      m_ShowStatus.Tag = MainContextMenuCommand.ShowStatus;

      m_ShowConfiguration = new ToolStripButton("Configuration", Resources.icon_menu_settings, OnMenuClick);
      m_ShowConfiguration.Tag = MainContextMenuCommand.ShowConfiguration;

      m_ShowAbout = new ToolStripButton("About application", Resources.icon_menu_about, OnMenuClick);
      m_ShowAbout.Tag = MainContextMenuCommand.ShowAbout;

      m_Exit = new ToolStripButton("Exit application", Resources.icon_menu_exit, OnMenuClick);
      m_Exit.Tag = MainContextMenuCommand.Exit;


      Items.AddRange(new ToolStripItem[] { m_ShowStatus, m_ShowConfiguration, m_ShowAbout, m_Exit });

      foreach(ToolStripItem item in Items) {
        item.AutoSize = false;
        item.Size = new Size(200, 36);
      }
    }

    void OnMenuClick(object sender, EventArgs e) {
      if (Command != null) {
        ToolStripButton button = (ToolStripButton)sender;
        Command.Invoke(this, new MainContextMenuEventArgs((MainContextMenuCommand)button.Tag));
      }
    }

    #region ILocalizable Members

    public void Localize(ILocalizator localizator) {
      if (localizator == null)
        throw new ArgumentNullException("localizator");

      m_Exit.Text = localizator.Translate("MainMenu_Exit");
      m_ShowConfiguration.Text = localizator.Translate("MainMenu_ShowConfiguration");
      m_ShowStatus.Text = localizator.Translate("MainMenu_ShowStatus");
      m_ShowAbout.Text = localizator.Translate("MainMenu_ShowAbout");
    }

    #endregion
  }
}
